set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/* *******************************************************************
** DATE :
** Writer :
** Memo :
******************************************************************** */
CREATE PROCEDURE [dbo].[TSP_StoreBest_GetInfo]
(
	@IsTransaction	tinyint			= 0
,	@ErrorCode		int				= 0		OUTPUT
,	@ErrorMessage	nvarchar( 1000 )= ''	OUTPUT

,	@n4StoreNo	int = null output--in

,	@strUserID	varchar(50) = null output
,	@strStoreName	nvarchar(100) = null output
,	@strCompanyNo	varchar(30) = null output
,	@strPhone	varchar(30) = null output
,	@strPost	varchar(10) = null output
,	@strAddress	nvarchar(200) = null output
,	@strCityName	nvarchar(10) = null output
,	@IsTakeout	char(1) = null output
,	@strTakeout	nvarchar(50) = null output
,	@strStoreSize	char(1) = null output
,	@strOpenDate	varchar(20) = null output
,	@strOpenTime	varchar(50) = null output
,	@strPointX	varchar(30) = null output
,	@strPointY	varchar(30) = null output
,	@strDescription	nvarchar(2000) = null output
,	@dtCreateDate	datetime = null output
,	@IsParking	char(1) = null output
,	@strParking	char(1) = null output
)
as
Set NOCOUNT ON

-- Frk Default Value
DECLARE @FrkDateNow DateTime
DECLARE @FrkRowCount int
DECLARE @FrkTranCount int
DECLARE @FrkErrorCode int
DECLARE @FrkErrorMessage nvarchar( 1000 )
Set @FrkDateNow = GetDate()
set @FrkTranCount = @@TRANCOUNT
-- Frk Check


If ( @IsTransaction = 0 )
Begin
	If ( @FrkTranCount < 1 )
	Begin
		Set @FrkErrorCode = -1
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Else If ( @FrkTranCount > 1 )
	Begin
		Set @FrkErrorCode = -2
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
End
Else
Begin
	If ( @FrkTranCount <> 0 )
	Begin
		Set @FrkErrorCode = -3
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Begin Tran
End


SELECT
	@strUserID	= S.strUserID
,	@strStoreName	= S.strStoreName
,	@strCompanyNo	= S.strCompanyNo
,	@strPhone	= S.strPhone
,	@strPost	= S.strPost
,	@strAddress	= S.strAddress
,	@strCityName	= S.strCityName
,	@IsTakeout	= S.IsTakeout
,	@strTakeout	= S.strTakeout
,	@strStoreSize	= S.strStoreSize
,	@strOpenDate	= S.strOpenDate
,	@strOpenTime	= S.strOpenTime
,	@strPointX	= S.strPointX
,	@strPointY	= S.strPointY
,	@strDescription = S.strDescription
,	@dtCreateDate   = B.dtCreateDate
,	@IsParking	= S.IsParking
,	@strParking	= S.strParking

FROM	dbo.TB_StoreBest AS B WITH ( NOLOCK )
LEFT JOIN TB_Store AS S WITH ( NOLOCK )
ON	S.n4StoreNo = B.n4StoreNo
AND	S.IsActive  = 'Y'
WHERE
	B.n4StoreNo = @n4StoreNo

-- Frk Error Check
SELECT
	@FrkErrorCode = @@ERROR
,	@FrkRowCount = @@RowCount

-- End

COMPLETE:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Commit Tran
		End
	End
	SET @ErrorCode = 0
	SET @ErrorMessage = ''
	return 0
ERROR:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Rollback Tran
		End
	End
	SET @ErrorCode = @FrkErrorCode
	SET @ErrorMessage = @FrkErrorMessage
	return @FrkErrorCode
